package cn.bonoon.kernel.menus;

import java.util.Properties;

import cn.bonoon.kernel.util.StringHelper;

/**
 * 插件的版本信息，即如果定义了某些插件，如：源数据管理插件、图表插件等，
 * 可以通过"cn/bonoon/plugins.properties"文件来指定该插件的一些版本信息
 * 
 * @author jackson
 *
 */
public class VersionDefinition {
	
	private final static String UNKNOW_PLUGIN = "/res/images/unknow-plugin.png";
	
	private final String version;
	private final String name;
	private final String image;
	private final String company;
	private final String time;
	private final String team;
	private final String des;
	private final String phone;
	
	VersionDefinition(ServerResourceResolver resourceServer, Properties properties){
		
		version = properties.getProperty("about.version");
		company = properties.getProperty("about.company");
		phone =   properties.getProperty("about.phone");
		name =    properties.getProperty("about.name");
		time =    properties.getProperty("about.time");
		team =    properties.getProperty("about.team");
		des =     properties.getProperty("about.des");
		
		image = resourceServer.resource(properties.getProperty("about.image"), UNKNOW_PLUGIN);

	}
	
	public void parse(String id, int index, StringBuilder thuHtml, StringBuilder desHtml){
		
		thuHtml.append("<a style='padding:4px;border-style:none;border-width:0px;border-bottom-width:0px;' ");
		thuHtml.append("title='").append(name);
		thuHtml.append("' href='#' id='thum-").append(id).append('-').append(index);
		thuHtml.append("'><img height='32' src='").append(image).append("'/></a>");
		
		desHtml.append("<table id='des-thum-").append(id).append('-').append(index);
		desHtml.append("' style='width:100%;display:none;' border='0' cellpadding='0' cellspacing='0'>");
		desHtml.append("<tr><td rowspan='5' align='center' valign='top' style='width:80px;'>");
		desHtml.append("<img src='").append(image).append("' height='64'/>");
		desHtml.append("</td><td align='right' style='width:60px;'><b>版本：</b></td><td>").append(version);
		desHtml.append("</td></tr><tr><td align='right'><b>名称：</b></td><td>").append(name).append("</td></tr>");
		
		if(StringHelper.isNotEmpty(company)){
			desHtml.append("<tr><td align='right'><b>公司：</b></td><td>").append(company);
			if(StringHelper.isNotEmpty(phone)){
				desHtml.append("(联系电话：").append(phone).append(')');
			}
			desHtml.append("</td></tr>");
		}
		
		if(StringHelper.isNotEmpty(team)){
			desHtml.append("<tr><td align='right'><b>团队：</b></td><td>").append(team);
			if(StringHelper.isNotEmpty(time)){
				desHtml.append("(时间：").append(time).append(')');
			}
			desHtml.append("</td></tr>");
		}
		
		if(StringHelper.isNotEmpty(des)){
			desHtml.append("<tr><td align='right'><b>说明：</b></td><td>").append(des).append("</td></tr>");
		}
		
		desHtml.append("</table>");
	}

}
